﻿using System;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;

namespace AnyOffice.general.system.mytable
{
    public partial class mytable_edit : ModulePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                int moduleId = (Request.QueryString["module_id"] != null) ? int.Parse(Request.QueryString["module_id"].ToString()) : 0;
                this.ViewState["ModuleId"] = moduleId;
                DataTable table = new MyTableDao().SelectByModuleId(base.Conn, moduleId);
                if (table.Rows.Count > 0)
                {
                    this.litModuleName.Text = table.Rows[0]["ModuleName"].ToString();
                    if (this.ddlModulePos.Items.FindByValue(table.Rows[0]["ModulePos"].ToString()) != null)
                    {
                        this.ddlModulePos.Items.FindByValue(table.Rows[0]["ModulePos"].ToString()).Selected = true;
                    }
                    this.txtModuleNo.Text = table.Rows[0]["ModuleNo"].ToString();
                    if (this.ddlViewType.Items.FindByValue(table.Rows[0]["ViewType"].ToString()) != null)
                    {
                        this.ddlViewType.Items.FindByValue(table.Rows[0]["ViewType"].ToString()).Selected = true;
                    }
                }
                else
                {
                    this.pnlMain.Visible = false;
                    this.litMessage.Text = base.ShowPrompt("无模块记录", "mytable.aspx");
                }
            }
            if (this.Page.IsPostBack)
            {
                new MyTableDao().Update(base.Conn, Convert.ToInt32(this.ViewState["ModuleId"].ToString()), this.ddlModulePos.SelectedValue, this.txtModuleNo.Text, Convert.ToInt32(this.ddlViewType.SelectedValue));
                ApplicationCache.Update();
                base.CloseConn();
                Response.Redirect("index.aspx");
            }
        } 

    }
}
